﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../lib/html5.js"></script>
    <script type="text/javascript" src="../lib/respond.min.js"></script>
    <script type="text/javascript" src="../lib/PIE_IE678.js"></script>
    <![endif]-->
    <link href="../../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../../lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <link href="../../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->

    <title>追溯</title>
    <link rel="stylesheet" type="text/css" href="../css/huisp.css" />
    <style type="text/css">
        body {
            background: #FFF;
        }

        .line {
            height: 20px;
        }
    </style>
</head>
<body>
    <header class="hui-header">
        <div id="hui-back"></div>
        <h1>采摘入库管理</h1>
    </header>
    <div class="hui-wrap">

        <div class="hui-content" style="padding:10px;">
            <form id="itemEdit" name="itemEdit" method="post" action="../../ashx/spui.ashx" class="form form-horizontal">
                <input type="hidden" id="hcrainbackid" name="hcrainbackid" value="1" />
                <input type="hidden" class="actionValue" id="editAction" name="action" value="add" />
                <input type="hidden" id="id" name="id" />
                <input type="hidden" id="actionaddlistids" name="actionaddlistids" value="ftaskid,finfoid,finfofv1,finfonv1" /><!--当为批量操作时（批量插入时）这几个数据为,分隔处理，作业批量的依据-->
                <input type="hidden" id="tablename" name="tablename" value="hsc_task_info" />
                <input type="hidden" id="tablemidname" name="tablemidname" value="id" />
                <input type="hidden" id="dataneedtouser" name="dataneedtouser" value="1" /><!--是否要包含通用数据必归属处理-->
                <!-- <input type="hidden" id="finfoid" name="finfoid" value="" />-->
                <input type="hidden" id="finfofv1" name="finfofv1" value="" />
                <input type="hidden" id="fcsgetpc" name="fcsgetpc" value="" />

                <input type="hidden" id="ftaskid" name="ftaskid" value="" />

                <div class="row cl">
                    <label class="form-label col-4">地块信息：</label>
                    <!--  <div class="formControls col-3">
                        <input type="text" class="input-text" name="fmaindcinfo" id="fmaindcinfo" readonly="readonly" placeholder="右边选择或搜索选择" />
                    </div>-->
                    <div class="formControls col-8  layui-form">
                        <select name="finfoid" id='finfoid' lay-filter="finfoid" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                </div>
                <div class="row cl" style="display: none;">

                    <label class="form-label col-1">采品：</label>
                    <div class="formControls col-5  layui-form">
                        <select name="selectspinfo" id='selectspinfo' lay-filter="selectspinfo" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-4">任务信息：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="fthistaskinfo" id="fthistaskinfo" readonly="true" style="background-color: #cccccc;" />
                    </div>
                    <div class="formControls col-4"></div>
                    <div class="formControls col-8  layui-form">
                        <select name="selecttaskinfo" id='selecttaskinfo' lay-filter="selecttaskinfo" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>

                </div>


                <div class="row cl">
                    <label class="form-label col-4">采收时间：</label>
                    <div class="formControls col-8">
                        <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="finfodt1" id="finfodt1" class="input-text Wdate" />
                    </div>

                    <label class="form-label col-1" style="display: none;">结束时间：</label>
                    <div class="formControls col-2" style="display: none;">
                        <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="finfodt2" id="finfodt2" class="input-text Wdate" />
                    </div>
                </div>
              
                <div class="row cl" style="display: none;">
                    <label class="form-label col-1">作业工具：</label>
                    <div class="col-2 layui-form">
                        <select name="finfofv5" id='finfofv5' lay-filter="testselect2" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                    <label class="form-label col-1">作业说明：</label>
                    <div class="formControls col-5">
                        <input type="text" class="input-text" name="finfofv6" id="finfofv6" />
                    </div>
                </div>
                <div class="row cl" style="display: none;">
                    <label class="form-label col-1">投入品：</label>
                    <div class="col-2 layui-form">
                        <select name="ftjpid" id='ftjpid' lay-filter="ftjpid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                        <input type="hidden" id="ftjpname" name="ftjpname" value="" />
                        <input type="hidden" id="ftjpunit" name="ftjpunit" value="" />
                    </div>
                    <label class="form-label col-1">投入量：</label>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" name="ftjpcount" id="ftjpcount" placeholder="投入量" value="0" />
                    </div>
                    <label class="form-label col-1">单价：</label>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" name="ftjpprice" id="ftjpprice" placeholder="单价" value="0" />
                    </div>
                </div>
                <div class="row cl" style="display: none;">
                    <label class="form-label col-1">出库品：</label>
                    <div class="col-3">
                        <input type="text" class="input-text" name="fplantjpstoreinfo" id="fplantjpstoreinfo" readonly="true" style="background-color: #cccccc;" />
                    </div>
                    <div class="col-2 layui-form">
                        <select name="fplantjpstoreid" id='fplantjpstoreid' lay-filter="fplantjpstoreid" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>

                        <input type="hidden" id="fplantjpstorename" name="fplantjpstorename" value="" />
                        <input type="hidden" id="fplantjpstoreunit" name="fplantjpstoreunit" value="" />
                    </div>
                    <label class="form-label col-1">数量：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="fplantjpcount" id="fplantjpcount" placeholder="数量" value="0" />
                    </div>
                    <label class="form-label col-1">单价：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="fplantjpprice" id="fplantjpprice" placeholder="单价" value="0" />
                    </div>
                </div>
                <div class="row cl" id="divtrfor8" style="display: none;">
                    <!--植保特殊数据-->
                    <label class="form-label col-1">防治对象：</label>
                    <div class="col-2 layui-form">
                        <select name="finfofv10" id='finfofv10' lay-filter="testselect5" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                </div>
                <div class="row cl" id="divtrfor6" style="display: none;">
                    <!--播种特殊数据-->
                    <label class="form-label col-1">播种方式：</label>
                    <div class="formControls col-1">
                        <span class="select-box">
                            <select class="select" name="finfofv9" id="finfofv9">
                                <option value="直播">直播</option>
                                <option value="移植">移植</option>
                            </select>
                        </span>
                    </div>
                    <label class="form-label col-1">播种量：</label>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" name="finfonv2" id="finfonv2" placeholder="播种量" value="0" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                    </div>
                    <div class="col-1"></div>
                </div>
                <div class="row cl" id="divtrfor11">
                    <!--采摘特殊数据-->
                    <label class="form-label col-4">采摘框数：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="finfonv6" id="finfonv6" placeholder="采摘框数" value="" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-4">采摘重量：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="finfonv3" id="finfonv3" placeholder="采摘重量" value="" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-4">入库量：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="finfonv5" id="finfonv5" placeholder="入库量" value="" datatype="/^-?[1-9]+(\.\d+)?$|^-?0(\.\d+)?$|^-?[1-9]+[0-9]*(\.\d+)?$/" />
                    </div>
                </div>

                <label class="form-label col-1" style="display: none;">采摘状态：</label>
                <div class="formControls col-2" style="display: none;">
                    <input type="text" class="input-text" name="finfofv11" id="finfofv11" readonly="true" value="已入库" style="background-color: #cccccc;" />
                </div>
                <div class="formControls col-1"></div>





                <div class="row cl" style="display: none;">
                    <label class="form-label col-1">工时：</label>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" name="fworktime" id="fworktime" placeholder="工时" value="0" />
                    </div>
                    <label class="form-label col-1">工时单价：</label>
                    <div class="formControls col-2">
                        <input type="text" class="input-text" name="fworktimeprice" id="fworktimeprice" placeholder="工时单价" value="0" />
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-6 col-offset-5">
                        <button class="btn btn-primary radius" type="submit" id="btsub1">提交</button>
                        <button onclick="hui.back();" class="btn btn-default radius" type="button">返回</button>
                    </div>
                </div>
                <div class="row cl">
                    <input type="hidden" id="finfofv2" name="finfofv2" />
                    <label class="form-label col-4">作业人员：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="finfofv3" id="finfofv3" readonly="readonly" placeholder="右边选择或搜索选择" />

                    </div>
                    <div class="formControls col-4"></div>
                    <div class="formControls col-8 layui-form">
                        <select name="inoutusernamesel" id='inoutusernamesel' lay-filter="testselect" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                        </select>
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-1" style="display: none;">作业类型：</label>
                    <div class="formControls col-2 layui-form" style="display: none;">
                        <!-- <select name="finfotypeid" id='finfotypeid' lay-filter="finfotypeid" lay-search="">
                <option value="">直接选择或搜索选择</option>
            </select>-->
                        <input type="hidden" id="finfotypeid" name="finfotypeid" value="" />
                        <input type="hidden" id="finfotypename" name="finfotypename" value="" />
                        <input type="hidden" id="finfotype" name="finfotype" value="" />
                        <input type="hidden" id="finfobytype1" name="finfobytype1" value="" />
                    </div>
                    <label class="form-label col-4">作业面积：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" name="finfonv1" id="finfonv1" placeholder="作业面积" value="0" />
                    </div>
                </div>
                <div class="row cl">
                    <label class="form-label col-4">备注：</label>
                    <div class="formControls col-8">
                        <input type="text" class="input-text" placeholder="入库说明" value="采摘直接入库" id="finfofv12" name="finfofv12" />
                    </div>
                </div>
                <div class="row cl" id="div1" style="display: none;">
                    <!--采摘特殊数据-->
                    <label class="form-label col-1" id="lablegg1">规格1：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="add_bj1" id="add_bj1" placeholder="规格1数量" value="0" onchange="recountccl();" datatype="/^\d+(\.\d+)?$/" />
                    </div>
                    <div class="formControls col-1"></div>
                    <label class="form-label col-1" id="lablegg2">规格2：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="add_bj2" id="add_bj2" placeholder="规格2数量" value="0" onchange="recountccl();" datatype="/^\d+(\.\d+)?$/" />
                    </div>
                    <div class="formControls col-1"></div>
                    <label class="form-label col-1" id="lablegg3">规格3：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="add_bj3" id="add_bj3" placeholder="规格2数量" value="0" onchange="recountccl();" datatype="/^\d+(\.\d+)?$/" />
                    </div>
                    <div class="formControls col-1"></div>
                    <label class="form-label col-1" id="Label1">出成量：</label>
                    <div class="formControls col-1">
                        <input type="text" class="input-text" name="add_cc" id="add_cc" placeholder="出成量" value="0" datatype="/^\d+(\.\d+)?$/" />
                    </div>
                    <div class="formControls col-1"></div>
                </div>
            </form>

        </div>
        <div style="padding:28px 10px;" class="hui-form" id="form1">
            <div class="hui-form-items" style="height:280px;">

            </div>


        </div>
    </div>
    <script src="../js/hui.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="../../lib/layui/layui2.js"></script>
    <script type="text/javascript" src="../../js/vue.min.js"></script>
    <script>
        var hcvueapp = new Vue({
            el: '#hcvueapp',
            data: {
                message: '<h1>菜鸟教程</h1>',
                listinfo: []
            },
            methods: {

            }
        })
    </script>
    <script src="../../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../../lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="../../lib/Validform/5.3.2/Validform.js"></script>
    <script type="text/javascript" src="../../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../../lib/My97DatePicker/WdatePicker.js"></script>
    <script src="../../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../js/hcui.js"></script>
    <script type="text/javascript" src="../../js/hcui_list.js"></script>
    <script type="text/javascript" src="../../js/hcui_au.js"></script>

    <script type="text/javascript">
        spPageUrl = "../../ashx/spui.ashx";
        base_ashx_url = "../../ashx/sp.ashx";
        var uiform = null;
        var selectTaskInfo = [];
        var whereaddinfo = "";
        hcui_ajaxasync = false;
        $(function () {
            spsetBaseNoBt("yw_baseinfo", "id", "yw_baseinfo as T", "*", "#tablelist", "sctaskintostore", "生产任务管理", "sctaskintostore");
            layui.use(['form'], function () {
                uiform = layui.form();
                hcdoselbyPost("id,fv1 as name", "yw_baseinfo", "type=1 and maintype=1", "", "", "id", function (data) {
                    SetSelectWithArrayIdName("#selectspinfo", data);
                    if (uiform) uiform.render('');//这个好像不用再保留了
                });

                //采品选择加载任务
                uiform.on('select(selectspinfo)', function (data) {
                    loadtaskspid = data.value;
                    loadtaskinfo();
                });
                //地块选择加载任务
                uiform.on('select(finfoid)', function (data) {
                    $('#finfoid').val(data.value);
                    $('#finfofv1').val(hcgetJsonObjById(selectInfoDc, data.value).fv1);
                    if (hcgetJsonObjById(selectInfoDc, data.value).fv19) {//采收人
                        $("#inoutusernamesel").val(hcgetJsonObjById(selectInfoDc, data.value).fv19);
                        $('#finfofv2').val(hcgetJsonObjById(selectInfoDc, data.value).fv19);
                        $('#finfofv3').val($("#inoutusernamesel").find("option:selected").text());
                    }
                    $('#fthistaskinfo').val("");
                    $('#ftaskid').val("");
                    $('#fthistaskinfo').val();
                    loadtaskinfoid = data.value;
                    loadtaskinfo();
                });
                //选择人员
                uiform.on('select(testselect)', function (data) {
                    $('#finfofv2').val(data.value);
                    $('#finfofv3').val($("#inoutusernamesel").find("option:selected").text());
                });

                //选择任务
                uiform.on('select(selecttaskinfo)', function (data) {
                    $('#ftaskid').val(data.value);
                    $('#finfonv1').val(hcgetJsonObjById(selectTaskInfo, data.value).taskmj);
                    $('#fthistaskinfo').val(hcgetJsonObjById(selectTaskInfo, data.value).name);
                    //加载规格
                    loadproducetgg();
                });
            });
            addloadInfo();
            // hcrainpage(1);
            $.Huitab("#tab-category .tabBar span", "#tab-category .tabCon", "current", "click", "0");
            $.Huifold("#Huifold2 .item h4", "#Huifold2 .item .info", "", 3, "click"); /*5个参数顺序不可打乱，分别是：相应区,隐藏显示的内容,速度,类型,事件 mouseover click */
        });
        var loadtaskinfoid = "";
        var loadtaskspid = "";
        function loadtaskinfo() {
            $('#ftaskid').val("");
            $('#finfonv1').val(0);
            $('#fthistaskinfo').val("");
            var whereinfo = " 1=1";
            whereinfo += " and databranchid=" + HCUser.HCUorg;
            if (loadtaskinfoid != "") {
                whereinfo += " and infoid=" + loadtaskinfoid;
            }
            if (loadtaskspid != "") {
                whereinfo += " and tasksctype=" + loadtaskspid;
            }
            //任务信息
            hcdoselbyPost("id,concat(tasksctypename,'-',taskno) as name,taskmj,taskno,tasksctype,tasksctypename", "view进行中的任务", whereinfo, "", "", "id",
                   function (data) {

                       data.splice(0, 0, { "id": "", "name": "选择任务" });
                       selectTaskInfo = data;
                       SetSelectWithArrayIdName("#selecttaskinfo", data);
                       if (getUrlParam("urltaskid")) {
                           $('#ftaskid').val(getUrlParam("urltaskid"));
                           $('#finfonv1').val(hcgetJsonObjById(selectTaskInfo, getUrlParam("urltaskid")).taskmj);
                           $('#fthistaskinfo').val(hcgetJsonObjById(selectTaskInfo, getUrlParam("urltaskid")).name);
                           //加载规格
                           loadproducetgg();
                       }
                       else if (data.length > 1) {
                           //默认加第2个
                           console.log(selectTaskInfo[1]);
                           $('#ftaskid').val(selectTaskInfo[1].id);
                           $('#finfonv1').val(selectTaskInfo[1].taskmj);
                           $('#fthistaskinfo').val(selectTaskInfo[1].name);
                       }

                       if (uiform) uiform.render('select');
                   });
        }
        function savetotaskstre() {
            var needupdate = 0;
            var updatecount = 0;
            var pcgid = NewGuid();
            for (var sp in hcvueapp.listinfo) {
                var subinfo = hcvueapp.listinfo[sp].subinfo;
                for (var lindex in subinfo) {
                    if (subinfo[lindex].infofv11 == "已入库" ||
                        subinfo[lindex].wantincount == null || subinfo[lindex].wantincount == "" || subinfo[lindex].wantincount == " " || isNaN(subinfo[lindex].wantincount)) {
                        continue;
                    }
                    var addinfo = "inouttype%采摘入库$productstate%原料"
                        + "$gid%" + pcgid//批次
                        + "$remarks%" + $("#postdesc").val()//备注
                        + "$outstate%待出库"//默认状态
                        + "$dkid%" + subinfo[lindex].infoid//地块ID
                        + "$dkname%" + subinfo[lindex].infofv1//地块编号
                        + "$taskid%" + subinfo[lindex].id//任务ID
                        + "$taskno%" + subinfo[lindex].taskno//任务编号
                        + "$tasklistid%" + subinfo[lindex].listid//采摘明细ID
                        + "$taskworktime%" + subinfo[lindex].infodt1.Value//采摘时间
                        + "$storehouseid%0$hasoutall%0"//默认初始化
                        + "$productid%" + hcvueapp.listinfo[sp].id//品种ID
                        + "$productname%" + hcvueapp.listinfo[sp].fv1//品种名称
                        + "$taskfromorgid%" + HCUser.HCUorg
                        + "$taskfromorgname%" + HCUser.HCUorgName
                        + "$storeall%" + subinfo[lindex].wantincount;//入库量

                    //入库处理-这里要禁用异步，同一客户端并发服务时，异步反面会慢？
                    hcdoadd2017("hsc_task_store", addinfo, 1, "", function (info) {//"{'settype':1,'byfile_name':'tasklistid'}"
                        //更新记录--已入库
                        if (info == "ok") {
                            updatecount++;
                            hcdoedit("hsc_task_info", "id", subinfo[lindex].listid,
                            "infofv11%已入库$infonv5%" + subinfo[lindex].wantincount, function (info2) { });
                        }
                        else { console.log(info); }

                    });

                }
            }
            layer.msg('完成入库操作，记录数：' + updatecount, { icon: 1 });
            //重新加载
            if (updatecount > 0) {
                hcrainpage(1);
            }


        }
        function hcrainpage(curr) {
            var finddcno = $("#findfv1").val();
            var findinfofv4 = $("#findinfofv4").val();
            if (finddcno) {
                whereaddinfo = " and fv1 like '%" + finddcno + "%'";
            }
            else { whereaddinfo = ""; }
            $.ajax({
                type: "post",
                url: "../ashx/spui.ashx",
                data: {
                    "action": "getpageinfo",
                    "pagenow": curr || 1,
                    "pagesize": 50,
                    "select": "t.id,t.fv1,t.fv2",
                    "table": "yw_baseinfo as t",
                    "group": "",
                    "having": "",
                    "where": " type=1 and maintype=1 " + whereaddinfo + " and id in(select tasksctype from view进行中的作业 where  taskstatus in ('计划','种植','作业','生产') and databranchid=" + HCUser.HCUorg + " and infotype=11  and infofv11='" + findinfofv4 + "')",//过滤采摘的信息
                    "order": "",
                    "subinfo": "id,taskno,tasksctype,tasksctypename,taskstatus,listid,infoid,infofv1,infofv4,infofv11,infonv1,infonv2,infonv3,infonv3 as wantincount,infonv5,infodataaddtime,infodt1#view进行中的作业#tasksctype-@id,infotype-11,infofv11-" + findinfofv4 + ",databranchid-" + HCUser.HCUorg + "#id#"//子查询  当前机构 当前物品
                },
                async: true,
                cache: false,
                error: function (error) {
                },
                success: function (data) {
                    var result = JSON.parse(data);
                    hcvueapp.listinfo = result.data;
                    if (hcvueapp.listinfo == null || hcvueapp.listinfo.length == 0) {
                        //layer.msg('没有更多数据了', { icon: 5});
                    }
                    //显示分页
                    laypage({
                        cont: 'page1', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                        pages: result.message || 0, //通过后台拿到的总页数
                        curr: curr || 1, //当前页
                        jump: function (obj, first) { //触发分页后的回调
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                hcrainpage(obj.curr);
                            }
                        }
                    });

                }
            });
        };

        //重新加载-重载
        function findreolad(isback) {
            hcrainpage(1);
        }


        //8888888888888888888888以下为添加入库
        var selectInfoDc = [];
        function addloadInfo() {
            $('#finfotypeid').val(948);
            $('#finfotypename').val("采收");
            $('#finfotype').val(11);//一级
            $('#finfobytype1').val(11);//二级
            $("#finfodt1").val(new Date().Format("yyyy-MM-dd"));//开始时间
            $("#finfodt2").val(new Date().Format("yyyy-MM-dd"));//结束时间

            hcdoselbyPost("id,concat(fv1,'-',fv9,'-',fv6) as name,nv1,fv1,fv8,fv10,fv7,fv9,fv6,fv4,fv19", "yw_baseinfo", "type=2 and maintype=2 and databranchid=" + HCUser.HCUorg, "", "", "id",
                 function (data) {
                     // data.splice(0, 0, { "id": "", "name": "选择地块" });
                     SetSelectWithArrayIdName("#finfoid", data);
                     selectInfoDc = data;
                     if (uiform) uiform.render('select');

                     $('#finfoid').val(getUrlParam("urldcid"));
                     $('#finfofv1').val(hcgetJsonObjById(selectInfoDc, getUrlParam("urldcid")).fv1);
                     $('#fthistaskinfo').val("");
                     $('#ftaskid').val("");
                     loadtaskinfoid = getUrlParam("urldcid");
                     loadtaskinfo();
                 });

            //人员下拉加载

            hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                function (data) {

                    SetSelectWithArrayIdName("#inoutusernamesel", data);
                    if (uiform) uiform.render('select');
                    if (hcgetJsonObjById(selectInfoDc, loadtaskinfoid).fv19) {//采收人
                        $("#inoutusernamesel").val(hcgetJsonObjById(selectInfoDc, loadtaskinfoid).fv19);
                        $('#finfofv2').val(hcgetJsonObjById(selectInfoDc, loadtaskinfoid).fv19);
                        $('#finfofv3').val($("#inoutusernamesel").find("option:selected").text());
                    }
                    else {
                        //默认的人员
                        $("#inoutusernamesel").val(HCUser.HCUide);
                        $('#finfofv2').val(HCUser.HCUide);
                        $('#finfofv3').val($("#inoutusernamesel").find("option:selected").text());
                    }

                });

        }
        // 日期，在原有日期基础上，增加days小时，默认增加1
        function addDate(date, days) {
            if (days == undefined || days == '') {
                days = 1;
            }
            var date = new Date(date);
            date.setHours(date.getHours() + days);
            return date;
            //var month = date.getMonth() + 1;
            //var day = date.getDate();
            //return date.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day);
        }

        //重写  提交前数据处理
        function hcrBeforeSub() {
            //要替换默认的配置
            $('#editAction').val('add');
            $("#tablename").val('hsc_task_info');
            $("#tablemidname").val('id');

            //$("#fareaname").val($('#fareaid option:selected').text());
            if ($("#finfotypeid").val() == "") {
                layer.msg("请选择作业类型", { icon: 5 });
                return false;
            }
            if ($("#finfoid").val() == "") {
                layer.msg("请选择地块信息", { icon: 5 });
                return false;
            }
            if ($("#ftaskid").val() == "") {
                layer.msg("请选择生产任务信息", { icon: 5 });
                return false;
            }
            $("#fcsgetpc").val(HCUser.HCUorg
              + "_" + $('#finfoid').val()
              + "_" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctype
              + "_" + $('#finfodt1').val());
        }
        //提交数据后,回调
        function subback(data) {
            hcui_ajaxasync = false;

            if (data.status == "y") {
                var hasoutall = "0";
                if ($("#c_dcinfo").is(':checked') && $("#add_cc").val() * 1 > 0)//是直接加工完成
                {
                    hasoutall = $('#finfonv5').val();
                }
                var pcgid = NewGuid();
                //插入库存
                var addinfo = "inouttype%采摘入库$productstate%原料"
                      + "$gid%" + pcgid//批次
                      + "$remarks%" + $("#finfofv12").val()//备注
                      + "$outstate%待出库"//默认状态
                      + "$dkid%" + $('#finfoid').val()//地块ID
                      + "$dkname%" + $('#finfofv1').val()//地块编号
                      + "$taskid%" + $('#ftaskid').val()//任务ID
                      + "$taskno%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).taskno//任务编号
                      + "$tasklistid%" + data.info//采摘明细ID
                      + "$taskworktime%" + $('#finfodt1').val() //采摘时间
                      + "$storehouseid%0$hasoutall%" + hasoutall//默认初始化
                      + "$productid%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctype//品种ID
                      + "$productname%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctypename//品种名称
                      + "$taskfromorgid%" + HCUser.HCUorg
                      + "$taskfromorgname%" + HCUser.HCUorgName
                      + "$storeall%" + $('#finfonv5').val()//入库量
                      + "$csgetpc%" + $("#fcsgetpc").val();
                hcdoadd201703("hsc_task_store", addinfo, 1, "", "", 1, function (info) {
                    if (info.message == "0001") {
                        if ($("#c_dcinfo").is(':checked') && $("#add_cc").val() * 1 > 0)//是直接加工完成
                        {
                            var addinfo = "inouttype%采摘加工入库$productstate%包装品"
                           + "$gid%" + NewGuid()//批次
                           + "$remarks%" + $("#finfofv12").val()//备注
                           + "$outstate%待出库"//默认状态
                           + "$dkid%" + $('#finfoid').val()//地块ID
                            + "$dkname%" + $('#finfofv1').val()//地块编号
                          + "$taskid%" + $('#ftaskid').val()//任务ID
                          + "$taskno%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).taskno//任务编号
                          + "$tasklistid%" + data.info//采摘明细ID
                          + "$taskworktime%" + $('#finfodt1').val() //采摘时间
                           + "$storehouseid%1$hasoutall%0"//默认初始化
                          + "$productid%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctype//品种ID
                          + "$productname%" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctypename//品种名称
                            + "$taskfromorgid%" + HCUser.HCUorg
                          + "$taskfromorgname%" + HCUser.HCUorgName
                           + "$datafromtable%hsc_task_store"
                           + "$datafromkeyid%" + info.data
                           + "$storealluseall%" + $('#finfonv5').val()
                           + "$storefortype1%" + $('#add_bj1').val()
                           + "$storefortype2%" + $('#add_bj2').val()
                           + "$storefortype3%" + $('#add_bj3').val()
                           + "$storeall%" + $('#add_cc').val()//入库量/出成量
                           + "$csgetpc%" + $("#infocsgetpc").val();
                            hcui_ajaxasync = false;
                            //出库处理-这里要禁用异步
                            hcdoadd2017("hsc_task_store", addinfo, 1, "", function (info) {
                                if (info == "ok") {
                                    layer.msg("入库并加工记录完成!", { icon: 1 });
                                }
                                else
                                    layer.msg(info, { icon: 2 });
                            });
                        }
                        else { layer.msg("采摘入库完成!", { icon: 1 }); }
                    }
                    else
                        layer.msg(info.data, { icon: 2 });
                });

                $("#finfonv3").val("");
                $("#finfonv5").val("");
                $("#finfonv6").val("");
            }
            else { layer.msg(data.info, { icon: 2 }); }
        }
        //加载规格
        var sp_gg1 = 0;
        var sp_gg2 = 0;
        var sp_gg3 = 0;
        function loadproducetgg() {
            sp_gg1 = 0;
            sp_gg2 = 0;
            sp_gg3 = 0;
            $('#lablegg1').html("");
            $('#lablegg2').html("");
            $('#lablegg3').html("");
            //id,fv1,fv2,fv3,nv1,nv2,nv3#yw_baseinfo#type-7,fv1-@id
            hcdoselbyPost("id,fv1,fv2,fv3,nv1,nv2,nv3", "yw_baseinfo", " type=7 and fv1=" + hcgetJsonObjById(selectTaskInfo, $('#ftaskid').val()).tasksctype, "", "", "nv2", function (data) {
                for (var index = 0; index < data.length; index++) {
                    if (index == 0) { $('#lablegg1').html(data[index].fv3); sp_gg1 = data[index].nv1; }
                    if (index == 1) { $('#lablegg2').html(data[index].fv3); sp_gg2 = data[index].nv1; }
                    if (index == 2) { $('#lablegg3').html(data[index].fv3); sp_gg3 = data[index].nv1; }
                }
            });
        }
        function recountccl() {
            $('#add_cc').val((sp_gg1 * $('#add_bj1').val() + sp_gg2 * $('#add_bj2').val() + sp_gg3 * $('#add_bj3').val()).toFixed(2));
        }

    </script>

</body>
</html>